package org.dtrd.modules.doctor.entity.bean;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.dtrd.config.system.Constant;
import org.dtrd.modules.control.entity.bean.PatientTargetReachStandardAvgRateDaily;
import org.dtrd.modules.record.entity.po.DtrdViewRlPatientSugarValue;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @author qr
 * @date 2022/4/14 15:05
 */
@ApiModel("患者首页动态部分信息")
@Getter
@Setter
public class DoctorIndexDynamicInfo {

    @ApiModelProperty("今日测量")
    private Integer todayCount = 0;
    @ApiModelProperty("今日测量差值")
    private Integer todayCountDifference = 0;

    @ApiModelProperty("今日异常")
    private Integer todayAbnormalCount = 0;
    @ApiModelProperty("今日异常差值")
    private Integer todayAbnormalCountDifference = 0;

    @ApiModelProperty("患者血糖信息数组")
    private List<PatientSugarValueInfo> valueInfos;

    @ApiModelProperty("血糖状况饼状图")
    private List<PieChartItem> sugarStatus;

    @ApiModelProperty("今日达标率")
    private List<BarChartItem> reachStandardRateBarChart;

    public DoctorIndexDynamicInfo parseFromDTO(PatientTargetReachStandardAvgRateDaily dto) {
        List<BarChartItem> list = new ArrayList<>(4);
        list.add(new BarChartItem("空腹血糖达标率", dto.getFbg()));
        list.add(new BarChartItem("糖化达标率", dto.getHba1c()));
        list.add(new BarChartItem("BMI达标率", dto.getBmi()));
        list.add(new BarChartItem("腰围达标率", dto.getWaist()));
        this.reachStandardRateBarChart = list;
        return this;
    }

    @ApiModel("患者血糖信息")
    @Getter
    @Setter
    public static class PatientSugarValueInfo{

        @ApiModelProperty("患者姓名")
        private String name;

        @ApiModelProperty("时间类型")
        private String time;

        @ApiModelProperty("血糖值")
        private Float value;

        @ApiModelProperty("血糖状态")
        private String tags;

        public PatientSugarValueInfo buildWithName(String patientName) {
            this.name = patientName;
            return this;
        }

        public PatientSugarValueInfo parseFromPO(DtrdViewRlPatientSugarValue po) {
            value = po.getSugarValueSugarValue();
            Optional.ofNullable(po.getSugarValueTimeTypeId()).ifPresent(s -> {
                Constant.SugarRecordType type = Constant.SugarRecordType.valueOf(s);
                assert type != null;
                this.time = type.getName() + "血糖";
            });
            Optional.ofNullable(po.getSugarValueType()).ifPresent(s -> this.tags = Constant.RecordStatus.valueOf(s).getName());
            return this;
        }
    }
}
